﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Clock
{
    class Program
    {
        delegate void Fun();
        //闹钟类
        public class MyClock
        {
            private int DueHour { get; set; }
            private int DueMinute { get; set; }
            private DateTime dateTime;
            /*public MyClock()
            {
                SetTime();
            }
            public void SetTime()
            {
                Console.WriteLine("请设置闹钟时间:");
                Console.WriteLine("时:");
                int dueHour = 0;
                while (!int.TryParse(Console.ReadLine(), out dueHour))
                {
                    DueMinute = dueHour;
                }
                while (DueMinute > 24 || DueMinute < 0)
                {
                    Console.WriteLine("设置错误，重新设置。时:");
                    if (int.TryParse(Console.ReadLine(),out dueHour)){
                        DueMinute = dueHour;
                    }
                }
                Console.WriteLine("分:");
                int dueMinute = 0;
                while (!int.TryParse(Console.ReadLine(), out dueMinute))
                {
                    DueMinute = dueMinute;
                }
                while (DueMinute > 24 || DueMinute < 0)
                {
                    Console.WriteLine("设置错误，重新设置。分:");
                    if (int.TryParse(Console.ReadLine(), out dueMinute))
                    {
                        DueMinute = dueMinute;
                    }
                }
                dateTime = DateTime.Now;
            }
            */
            public MyClock()
            {
                DueHour = DateTime.Now.Hour + (DateTime.Now.Minute + 1) / 60;
                DueMinute = (DateTime.Now.Minute + 1) % 60;
                dateTime = DateTime.Now;
            }
            public void Alarm()
            {
                if (dateTime.Hour == DueHour&&dateTime.Minute == DueMinute)
                { 
                    Console.WriteLine("猪头，上课时间到了");
                }
            }
            public void Tick()
            {
                while (dateTime.Hour <= DueHour && dateTime.Minute < DueMinute)
                {
                    Console.WriteLine(" "+ dateTime.ToString() + " Tick Tick Tick");
                    System.Threading.Thread.Sleep(1000);
                    dateTime = DateTime.Now;
                }
            }
        }
        static void Main(string[] args)
    {
            MyClock clock = new MyClock();
            Fun fun = new Fun(clock.Tick);
            fun += clock.Alarm;
            fun();
            return;
        }
    }
}
